﻿using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xrm.Solutions.FrameworkSample.Common.Entities;

namespace Xrm.Solutions.FrameworkSample.XrmIntegrationTests
{
    public class CrmHelpers
    {
        public static void SetConfigurationSetting(IOrganizationService organisationService, string key, string value)
        {
            using (XrmServiceContext xrmContext = new XrmServiceContext(organisationService))
            {
                var configSettings = from c in xrmContext.xdft_configurationSet
                                     where c.xdft_name == key
                                     select c;

                if (configSettings.ToList().Count == 0)
                {
                    xdft_configuration testConfig = new xdft_configuration();
                    testConfig.xdft_name = key;
                    testConfig.xdft_Value = value;

                    organisationService.Create(testConfig);
                }
            }
        }
    }
}
